package com.hotel.room.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hotel.room.pojo.Room;
import com.hotel.room.service.RoomService;

@RestController
@RequestMapping("/room/manage")
public class RoomController {
	@Autowired
	private RoomService roomService;

	@RequestMapping("/save")
	public String addRoom(Room room) {
		roomService.addRoom(room);
		return "sucess";
	}
	
	@RequestMapping("/delete")
	public String deleteRoom(int id) {
		roomService.deleteRoom(id);
		return "sucess";
	}
	@RequestMapping("update")
	public String updateRoom(Room room){
		roomService.updateRoom(room);
		return "sucess";
	}
	@RequestMapping("query")
	public List<Room> queryRoom(){
		return roomService.queryRoom();
	}
	@RequestMapping("queryById")
	public Room queryRoomById(int id){
		return roomService.queryRoomById(id);
	}
	
	
	//order调用
	//String uri1="http://roomservice/room/manage/selectRoomByType?roomType="+order.getRoomType();
	@RequestMapping("selectRoomByType")
	public Room selectRoomByType(String roomType){
		try{
			return roomService.selectRoomByType(roomType);
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	
	 //String url="http://roomservice/room/manage/updateRoomNumByType?roomType="+roomType+"&num="+num;
	@RequestMapping("updateRoomNumByType")
	public String updateRoomNumByType(String roomType,int num){
		try{
			roomService.updateRoomNumByType(num,roomType);
			return "success";
		}catch(Exception e){
			e.printStackTrace();
			return "fail";
		}
	}
}
